package com.jm.springboot21.controller;

import com.jm.springboot21.pojo.Dept;
import com.jm.springboot21.pojo.Emp;
import com.jm.springboot21.pojo.PageBean;
import com.jm.springboot21.pojo.Result;
import com.jm.springboot21.service.EmpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/emp")
@CrossOrigin("*")
public class EmpController {
    @Autowired
    private EmpService empService;
    @GetMapping
    public Result findAll(){
        List<Emp> all = empService.findAll();
        return Result.success(all);
    }
    @PostMapping
    public Result addEmp(@RequestBody Emp emp){
        empService.addEmp(emp);
        return Result.success();
    }
    @DeleteMapping("/{id}")
    public Result deleteById(@PathVariable Integer id){
        empService.deleteById(id);
        return Result.success();
    }
    @DeleteMapping
    public Result deleteByIds(@RequestBody List<Integer> ids){
        empService.deleteByIds(ids);
        return Result.success();
    }
    @PutMapping
    public Result updateById(@RequestBody Emp emp){
        empService.updateById(emp);
        return Result.success();
    }
    @GetMapping("/{id}")
    public Result findById(@PathVariable Integer id){
        Emp emp = empService.findById(id);
        return Result.success(emp);
    }
    @GetMapping("/name/{name}")
    public Result findByName(@PathVariable String name){
        List<Emp> emps = empService.findByName(name);
        return Result.success(emps);
    }
    @GetMapping("/count")
    public Result count(){
        Integer count = empService.count();
        return Result.success(count);
    }

}
